/* 
 * File:   Entity.h
 * Author: artem
 *
 * Created on November 17, 2011, 9:35 PM
 */

#ifndef ENTITY_H
#define ENTITY_H

#include "Common.h"
#include "Hitbox.h"

#include "math/mathgl.h"

#include "Render/Texture.h"
#include "Render/Model.h"

class Entity
{
public:
	Entity(): m_position(vec3_zero), m_angle(vec3_zero) {}
	
	const vec3 getPosition() const { return m_position; }
	void setPosition(const vec3 &position) { m_position = position; }
	
	const vec3 getAngle() const { return m_angle; }
	void setAngle(const vec3 &angle) { m_angle = angle; }
	
	const mat4 getTransform() const { return MatTranslation(m_position) * MatFromEuler(m_angle); }
	
	const Hitbox getHitbox() const { return m_hitbox; }
	void setHitbox(const Hitbox &hitbox) { m_hitbox = hitbox; }
	
	bool isCollide(const Entity *entity) const
	{
		if (!entity)
			return false;
		
		const vec3 pos = entity->getPosition();
		const Hitbox hitbox(
			m_hitbox.x + m_position.x - pos.x,
			m_hitbox.y + m_position.y - pos.y,
			m_hitbox.w,
			m_hitbox.h
		);
		
		return hitbox.isIntersect(entity->getHitbox());
	}
	
	const Render::Texture* getTexture() const { return m_texture; }
	void setTexture(const Render::Texture *texture) { m_texture = texture; }
	
	const Render::Model* getModel() const { return m_model; }
	void setModel(const Render::Model *model) { m_model = model; }
	
protected:
	vec3 m_position;
	vec3 m_angle;
	
	Hitbox m_hitbox;
	
	const Render::Texture *m_texture;
	const Render::Model   *m_model;
};

#endif /* ENTITY_H */
